package com.yisoo.ubag.app.controller;

import java.util.Arrays;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.yisoo.common.constant.LoginStatusConstant;
import com.yisoo.ubag.app.manager.WxApiManager;
import com.yisoo.ubag.app.to.UserInfoTo;
import com.yisoo.ubag.app.to.WxLoginResponseTo;
import com.yisoo.ubag.app.util.UniReqParseUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import com.yisoo.ubag.app.entity.UserEntity;
import com.yisoo.ubag.app.service.UserService;
import com.yisoo.common.utils.PageUtils;
import com.yisoo.common.utils.R;
import springfox.documentation.annotations.ApiIgnore;


/**
 * 
 *
 * @author mmciel
 * @email 761998179@qq.com
 * @date 2021-02-18 17:50:09
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("app/user")
public class UserController {
    @Autowired
    private UserService userService;



    //微信登录接口
    @PostMapping("/login/wx/{code}")
    @ApiOperation(value = "微信登录", notes = "根据code和userinfo登录微信")
    public R wxLogin(@PathVariable("code")String code,@RequestBody String data ){


        return userService.LoginAndReg(code,data);
    }

    @GetMapping("/login/test")
    @ApiOperation(value = "登录拦截测试", notes = "登录拦截测试")
    public R test(){
        return R.ok().put("data","/login/test");
    }
    @GetMapping("/test")
    @ApiOperation(value = "测试拦截效果", notes = "测试拦截效果")
    public R test2(){
        return R.ok().put("data","/test");
    }

    /**
     * 列表
     */
    @ApiIgnore
    @RequestMapping("/list")
    //@RequiresPermissions("app:user:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiIgnore
    @RequestMapping("/info/{appUserId}")
    //@RequiresPermissions("app:user:info")
    public R info(@PathVariable("appUserId") String appUserId){
		UserEntity user = userService.getById(appUserId);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @ApiIgnore
    @RequestMapping("/save")
    //@RequiresPermissions("app:user:save")
    public R save(@RequestBody UserEntity user){
		userService.save(user);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiIgnore
    @RequestMapping("/update")
    //@RequiresPermissions("app:user:update")
    public R update(@RequestBody UserEntity user){
		userService.updateById(user);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiIgnore
    @RequestMapping("/delete")
    //@RequiresPermissions("app:user:delete")
    public R delete(@RequestBody String[] appUserIds){
		userService.removeByIds(Arrays.asList(appUserIds));

        return R.ok();
    }

}
